<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>TreeUtil</title>
</head>
<body>

<script src="../../../lib/baitu.min.js"></script>
<script>

    const list = [
        {
            "deptId": 100,
            "parentId": 0,
            "deptName": "百涂科技",
            "children": []
        },
        {
            "deptId": 101,
            "parentId": 100,
            "deptName": "深圳总公司",
            "children": []
        },
        {
            "deptId": 102,
            "parentId": 100,
            "deptName": "长沙分公司",
            "children": []
        },
        {
            "deptId": 103,
            "parentId": 101,
            "deptName": "研发部门",
            "children": []
        },
        {
            "deptId": 104,
            "parentId": 101,
            "deptName": "市场部门",
            "children": []
        },
        {
            "deptId": 105,
            "parentId": 101,
            "deptName": "测试部门",
            "children": []
        },
        {
            "deptId": 106,
            "parentId": 101,
            "deptName": "财务部门",
            "children": []
        },
        {
            "deptId": 107,
            "parentId": 101,
            "deptName": "运维部门",
            "children": []
        },
        {
            "deptId": 108,
            "parentId": 102,
            "deptName": "市场部门",
            "children": []
        },
        {
            "deptId": 109,
            "parentId": 102,
            "deptName": "财务部门",
            "children": []
        }
    ]

    const list2 = [...list]

    const {TreeUtil} = Baitu;

    console.log(TreeUtil.buildTree(list, 'deptId', 'parentId', 'children'))
    console.log(TreeUtil.buildCommonTree(list, 'deptId', 'parentId', 'children'))

    console.log("-----------------")
    console.log(list2)
    TreeUtil.buildTreeMapper(list2, 'deptId', 'parentId', (current, parent, parentChilds, level) => {
        if (level !== 1) {
            parent['children'] = parentChilds;
        }
        current['level'] = level;
        return current;
    });
    console.log(list2)

</script>
</body>
</html>
